#include "CVImgUtils.h"
#include "cvimgutilslua.h"
#include "../core/LuaUtils.h"


void CVImgUtilsLua::pushStaticFuncs(lua_State* L)
{
	static const struct luaL_Reg mylib [] = {
		{"SaveImage", li_saveImage},
		{"LoadImage", li_loadImage},
		{"CreateImage", li_createImage},
		{NULL, NULL}  /* sentinel */
	};

	// dump them into said table
	luaL_register(L, NULL, mylib);
}

int CVImgUtilsLua::li_saveImage(lua_State* L)
{
	CVImgUtils* op = (CVImgUtils*)typeCheckUnboxAO(L,1,"CVImgUtils");
	if(op == NULL){
		LOG(logERROR) << "Null self!";
	return 0;}
	SimpleImage* a1 = pop_custom<SimpleImage>(L, 2, "SimpleImage");
	std::string a2 = lua_tostring(L, 3);
	op->saveImage(a1, a2);
	
	return 0;
}


int CVImgUtilsLua::li_loadImage(lua_State* L)
{
	CVImgUtils* op = (CVImgUtils*)typeCheckUnboxAO(L,1,"CVImgUtils");
	if(op == NULL){
		LOG(logERROR) << "Null self!";
	return 0;}
	std::string a1 = lua_tostring(L, 2);
	SimpleImage* ret = op->loadImage(a1);
	push_custom<SimpleImage>(L, ret, "SimpleImage");
	return 1;
}

int CVImgUtilsLua::li_createImage(lua_State* L)
{
	SimpleImage* ret = new SimpleImage;
	push_custom<SimpleImage>(L, ret, "SimpleImage");
	return 1;
}


